home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / Pen Play ƒ / pen play.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  8.4 KB  |  276 lines  |  [TEXT/KAHL]

  1. /*
  2.     pen play.c
  3.     
  4.     This application creates various paths. We will then apply different pen styles to each path. We play with
  5.     the pen size and location of the pen (i.e. on, inset, and outside of the geometry).
  6.      
  7.     NOTES:
  8.     • This file requires the following files to run correctly:
  9.         "graphics shell.c", "ColorLibrary.c", "GraphicsDebugLibrary.c",
  10.         "ShapeLibrary.c", "TransformLibrary.c".
  11.         
  12.     • This file prints the "best" in landscape mode.
  13.         
  14.     Change History:
  15.  
  16.        4/96    bob        Updated #includes to support changed GX Library names.
  17.                     Updated the note regarding the files needed to run.
  18.                     Updated the copyright date.
  19.  
  20.     ©1992 - 1996  Apple Computer, Inc.
  21.     All rights reserved.
  22. */
  23.  
  24. #include <events.h>
  25. #include <windows.h>
  26.  
  27. #include "FontLibrary.h"
  28. #include "GraphicsLibraries.h"
  29. #include <GXEnvironment.h>
  30. #include "graphics shell.h"
  31.  
  32. //
  33. //  Set up the title and size of the window 
  34. //
  35. Str255         gWindowTitle = "\p Pen Play...";
  36. Rect         gWindowQDRect  = {40, 10, 445, 575};
  37.  
  38. //
  39. //    gGraphicsHeapSize sets the size of the graphics heap created by calling the GXNewGraphicsClient routine
  40. //    in main () within graphics shell.c.  You can determine the amount of graphics heap required by using GraphicsBug.
  41. //    With gGraphicsHeapSize set to 135k, I had 15 free blocks left in the graphics heap. Sounds good to me.
  42. //
  43. long        gGraphicsHeapSize = 135;
  44.  
  45. gxShape     gThePage;
  46.  
  47.  
  48. //
  49. //    We use "gShapesInPicture"  in the DoDraw function. If we have added shapes to the picture, we draw it. Otherwise, we
  50. //    wait for the user to click in the window, thereby adding a gxShape to the picture.
  51. //
  52. Boolean        gShapesInPicture;
  53.  
  54.  
  55.  
  56. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  57.  
  58. void DoInitialization(gWindow)
  59. WindowPtr gWindow;
  60. {
  61.      gxShape     thePath;
  62.     long         tripleDumpGeometricData[] = {    1,             // number of contours 
  63.                                                   6,             // number of points
  64.                                                   0xff000000,
  65.                                                      0, 0,       // the points
  66.                                                      ff(75),  0, 
  67.                                                      ff(5), ff(50), 
  68.                                                      ff(75),  ff(100),  
  69.                                                     0,  ff(100), 
  70.                                                      ff(75), ff(50)};
  71.                                                              
  72.     long         ovalWabbleGeometricData[] = {     1,             // number of contours
  73.                                                    6,             // number of points
  74.                                                    0xff000000,
  75.                                                     0, 0,       // the points
  76.                                                     ff(150),  0, 
  77.                                                     ff(80), ff(100), 
  78.                                                     ff(150), ff(200),  
  79.                                                     0, ff(200), 
  80.                                                     ff(80), ff(100)};
  81.                                                             
  82.      long         figureEightGeometricData[] = {    1,             // number of contours
  83.                                                  6,            // number of points
  84.                                                  0xff000000,
  85.                                                    0, 0,         // the points
  86.                                                    ff(150),  0, 
  87.                                                    ff(75), ff(90), 
  88.                                                    0, ff(200), 
  89.                                                    ff(150), ff(200),  
  90.                                                    ff(75), ff(90)}; 
  91.                                                    
  92.     long         tripleEightGeometricData[] = {     1,             // number of contours
  93.                                                  6,            // number of points
  94.                                                  0xff000000,
  95.                                                    0, 0,          // the points
  96.                                                    ff(150),  0, 
  97.                                                    ff(10), ff(100), 
  98.                                                    ff(150), ff(200),  
  99.                                                   0, ff(200), 
  100.                                                    ff(150), ff(100)};        
  101.     short    loop,
  102.              newHLoc,
  103.              newPenWidth;
  104.              
  105.     InitCommonColors();
  106.  
  107.     //
  108.     //     Create the "gthePage" shape. We set the unique items attribute to make sure that each item added to the
  109.     //    picture has a unique reference. If this attribute was not set, we would not see all of the inset, outset, and on
  110.     //    geometry paths we create below.
  111.     //
  112.     gThePage = GXNewShape(gxPictureType);
  113.     GXSetShapeAttributes(gThePage, gxUniqueItemsShape);
  114.     
  115.     //
  116.     //     Create a gxPath which has: starting with a pen thickness of 0, it's gxColor is green, and it's drawn with it's frame.
  117.     //     We will then draw the gxPath 6 times with an increasing (from 2 through 14) pen width
  118.     //
  119.      newHLoc = 10;
  120.      newPenWidth = 3;
  121.                                                              
  122.     thePath = GXNewPaths((gxPaths *) tripleDumpGeometricData);
  123.     GXSetShapeFill (thePath, gxClosedFrameFill);
  124.      SetShapeCommonColor (thePath, blue);
  125.  
  126.     for (loop = 0; loop  < 8; loop ++) 
  127.     {    
  128.         GXMoveShapeTo (thePath,  ff(newHLoc), ff(15));
  129.         AddToShape(gThePage, thePath);
  130.                 
  131.         GXSetShapePen(thePath, ff(newPenWidth));
  132.                     
  133.         newPenWidth +=  2;
  134.         newHLoc += 70;
  135.     }
  136.     GXDisposeShape(thePath);  
  137.  
  138.     //
  139.     //     Create a gxPath which looks like an oval with the middle sides pushed in. We will then draw it with the the gxStyle set to: 
  140.     //     gxCenterFrameStyle, gxOutsideFrameStyle, and gxInsideFrameStyle.
  141.     //                                                          
  142.     thePath = GXNewPaths((gxPaths *) ovalWabbleGeometricData);
  143.     GXSetShapeFill (thePath, gxClosedFrameFill);
  144.      GXSetShapeStyleAttributes(thePath, gxOutsideFrameStyle);                    
  145.     GXSetShapePen(thePath, ff(6));
  146.     SetShapeCommonColor (thePath, red);
  147.  
  148.     GXMoveShapeTo (thePath,  ff(10), ff(160));
  149.         
  150.     for (loop = 0; loop  < 3; loop ++) 
  151.     {    
  152.         if (loop == 1) {
  153.            GXSetShapeStyleAttributes(thePath, gxInsideFrameStyle);                    
  154.            SetShapeCommonColor (thePath, green);
  155.         }    
  156.  
  157.         if (loop == 2) {
  158.             GXSetShapePen(thePath, ff(3));
  159.             GXSetShapeStyleAttributes(thePath, gxCenterFrameStyle);                    
  160.             SetShapeCommonColor (thePath, blue);
  161.         }    
  162.                         
  163.         AddToShape(gThePage, thePath);
  164.     }
  165.     GXDisposeShape(thePath);  
  166.  
  167.     //
  168.     //     Create a gxPath which looks like a figure eight. We will then draw it with the the style set to: 
  169.     //     gxCenterFrameStyle, gxOutsideFrameStyle, and gxInsideFrameStyle.
  170.     //
  171.     thePath = GXNewPaths((gxPaths *) figureEightGeometricData);
  172.     GXSetShapeFill (thePath, gxClosedFrameFill);
  173.      GXSetShapeStyleAttributes(thePath, gxOutsideFrameStyle);                    
  174.     GXSetShapePen(thePath, ff(6));
  175.     SetShapeCommonColor (thePath, red);
  176.  
  177.     GXMoveShapeTo (thePath,  ff(155), ff(160));
  178.  
  179.     for (loop = 0; loop  < 3; loop ++) 
  180.     {    
  181.         if (loop == 1) {
  182.             GXSetShapeStyleAttributes(thePath, gxInsideFrameStyle);                    
  183.             SetShapeCommonColor (thePath, green);
  184.         }    
  185.  
  186.         if (loop == 2) {
  187.             GXSetShapePen(thePath, ff(3));
  188.             GXSetShapeStyleAttributes(thePath, gxCenterFrameStyle);                    
  189.             SetShapeCommonColor (thePath, blue);
  190.         }    
  191.                         
  192.         AddToShape(gThePage, thePath);
  193.     }
  194.     GXDisposeShape(thePath);  
  195.  
  196.     //
  197.     //     Create a gxPath which looks like a figure eight with a 3rd loop. We will then draw it with the the style set to: 
  198.     //     gxCenterFrameStyle, gxOutsideFrameStyle, and gxInsideFrameStyle.
  199.     //
  200.     thePath = GXNewPaths((gxPaths *) tripleEightGeometricData);
  201.     GXSetShapeFill (thePath, gxClosedFrameFill);
  202.      GXSetShapeStyleAttributes(thePath, gxOutsideFrameStyle);                    
  203.     GXSetShapePen(thePath, ff(6));
  204.     SetShapeCommonColor (thePath, red);
  205.  
  206.     GXMoveShapeTo (thePath,  ff(300), ff(160));
  207.  
  208.     for (loop = 0; loop  < 3; loop ++) 
  209.     {    
  210.         if (loop == 1) {
  211.            GXSetShapeStyleAttributes(thePath, gxInsideFrameStyle);                    
  212.            SetShapeCommonColor (thePath, green);
  213.         }    
  214.  
  215.         if (loop == 2) {
  216.            GXSetShapePen(thePath, ff(3));
  217.            GXSetShapeStyleAttributes(thePath, gxCenterFrameStyle);                    
  218.            SetShapeCommonColor (thePath, blue);
  219.         }    
  220.                         
  221.         AddToShape(gThePage, thePath);
  222.     }
  223.     GXDisposeShape(thePath);  
  224. }
  225.  
  226.  
  227.  
  228. /*------ DoClick ---------------------------------------------------------------------------------------*/
  229.  
  230. void DoClick( orgMouseLoc, theWindow )
  231. gxPoint        orgMouseLoc;
  232. WindowPtr     theWindow;
  233. {
  234. }
  235.  
  236.  
  237.  
  238. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  239. //
  240. //    Draw the contents of "gthePage". 
  241. // 
  242. void DoDraw(gWindow)
  243. WindowPtr gWindow;
  244. {
  245.      GXDrawShape (gThePage);
  246. }
  247.  
  248.  
  249. /*------ DoDispose -------------------------------------------------------------------------------------*/
  250.  
  251. void DoDispose(gWindow)
  252. WindowPtr gWindow;
  253. {
  254.     /**  
  255.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  256.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  257.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  258.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  259.         can turn notices on in this file by setting gDebugging = TRUE (above).
  260.     **/
  261.     GXDisposeShape(gThePage);  
  262.      GXDisposeShape(gWindowBoundsShape);  
  263.        DisposeCommonColors();
  264.        DisposeWindow(gWindow);
  265. }
  266.     
  267.  
  268.  
  269.  
  270. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  271.  
  272. void DoIdle(gWindow)
  273. WindowPtr gWindow;
  274. {
  275. }
  276.